package com.linktel.productionLine.common;

import com.linktel.productionLine.exception.BusinessException;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import static com.linktel.productionLine.constant.CommonConstant.CURRENT_USER;

/**
 * 自定义拦截器
 * @author shengwu ni
 * @date 2018/08/03
 */
@Component
public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        HttpSession session = request.getSession();
        Object commitUser = session.getAttribute(CURRENT_USER);
        if (commitUser == null) {
            throw new BusinessException(ErrorCode.NOT_LOGIN_ERROR);
        }
        return true;
    }
}
